#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cnt = i;
        while (cnt)
        {
            int c = cnt % 10;
            if (c == 2 || c == 0 || c == 9 || c == 1)
            {
                sum += i;
                break;
            }
            cnt /= 10;
        }
    }
    cout << sum;
    return 0;
}